package com.wannengbang.cloudleader.homepage.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wannengbang.cloudleader.R;
import com.wannengbang.cloudleader.bean.QueryOrderListBean;
import com.wannengbang.cloudleader.homepage.TransactionQueryDetailsActivity;
import com.wannengbang.cloudleader.utils.DateTimeUtil;
import com.wannengbang.cloudleader.utils.NumberFormatUtils;

import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 合伙人列表
 */
public class TransQueryListAdapter extends RecyclerView.Adapter<TransQueryListAdapter.ViewHolder> {


    private List<QueryOrderListBean.DataBean.ItemListBean> listsBeans;
    private Context context;

    public TransQueryListAdapter(List<QueryOrderListBean.DataBean.ItemListBean> listsBeans) {
        this.listsBeans = listsBeans;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_tran_query_list, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        QueryOrderListBean.DataBean.ItemListBean dataBean = listsBeans.get(position);
        holder.tvTime.setText(DateTimeUtil.format7(new Date(Long.parseLong(dataBean.getCreate_time()) * 1000)));
        holder.tvAgentName.setText(dataBean.getMem_name());
        String money = NumberFormatUtils.formatTwoDecimal(Double.parseDouble(dataBean.getOrder_fee()) / 100);
        holder.tvMoney.setText("+" + money);
        holder.tvType.setText(dataBean.getTrans_type_text() + dataBean.getTrans_type_flag());
        holder.itemView.setOnClickListener(v -> {
            Intent intent = new Intent(context, TransactionQueryDetailsActivity.class);
            intent.putExtra("itemListBean", dataBean);
            context.startActivity(intent);
        });
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_agent_name)
        TextView tvAgentName;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.tv_type)
        TextView tvType;
        @BindView(R.id.tv_money)
        TextView tvMoney;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
